-- This file is part of the Fantasy Grounds Open Foundation Ruleset project. 
-- For the latest information, see http://www.fantasygrounds.com/
--
-- Copyright 2008 SmiteWorks Ltd.
--
-- This file is provided under the Open Game License version 1.0a
-- Refer to the license.html file for the full license text
--
-- All producers of work derived from this material are advised to
-- familiarize themselves with the license, and to take special
-- care in providing the definition of Product Identity (as specified
-- by the OGL) in their products.
--
-- All material submitted to the Open Foundation Ruleset project must
-- contain this notice in a manner applicable to the source file type.
--


function setRows(n)
	if n < 0 then
		return;
	end

	local windows = getWindows();
	
	if #windows > n then
		-- Need to close some entries
		for i = n+1, #windows do
			windows[i].close();
		end
		return;
	end
	
	-- Otherwise, need to create some
	for i = 1, n - #windows do
		createWindow();
	end
end

function updateTotals()
	local sum = 0;

	for k, w in ipairs(getWindows()) do
		local score = w.score.getValue();
		local points = calculatePointCost(score);
		
		w.points.setValue(points);
		
		sum = sum + points;
	end
	
	window.total.setValue(sum);
	
	if not window.ranges.hasNonzeroCosts() then
		window.costwarning.setVisible(true);
	else
		window.costwarning.setVisible(false);
	end
end

function calculatePointCost(score)
	return window.ranges.calculatePointCost(score);
end
